package top.yueyazhui.vhr.controller.Sys.SysBasic;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.yueyazhui.vhr.bean.Response;
import top.yueyazhui.vhr.model.JobLevel;
import top.yueyazhui.vhr.service.JobLevelService;

import java.util.List;

@RestController
@RequestMapping("/Sys/SysBasic/JobLevel")
@Api(tags = "职称")
public class JobLevelController {
    @Autowired
    JobLevelService jobLevelService;

    @GetMapping("/")
    @ApiOperation(value = "查询所有职称", notes = "查询所有职称")
    public List<JobLevel> getAll() {
        return jobLevelService.getAll();
    }

    @PostMapping("/")
    @ApiOperation(value = "创建职称", notes = "创建职称")
    public Response insert(@RequestBody JobLevel jobLevel) {
        if(jobLevelService.insert(jobLevel) == 1) {
            return Response.success("添加成功！");
        }
        return Response.error("添加失败！");
    }

    @PutMapping("/")
    @ApiOperation(value = "编辑职称", notes = "根据职称编号编辑职称")
    public Response update(@RequestBody JobLevel jobLevel) {
        if(jobLevelService.update(jobLevel) == 1) {
            return Response.success("更新成功！");
        }
        return Response.error("更新失败！");
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除职称", notes = "根据职称编号删除职称")
    @ApiImplicitParam(name = "id", value = "职称编号", required = true)
    public Response delete(@PathVariable Integer id) {
        if(jobLevelService.delete(id) == 1) {
            return Response.success("删除成功！");
        }
        return Response.error("删除失败！");
    }

    @DeleteMapping("/")
    @ApiOperation(value = "批量删除职称", notes = "根据职称编号批量删除职称")
    public Response batchDelete(Integer[] ids) {
        if(jobLevelService.batchDelete(ids) == ids.length) {
            return Response.success("删除成功！");
        }
        return Response.error("删除失败！");
    }
}
